package com.sunnada.edu.business.attendance.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.sunnada.edu.business.attendance.bean.AttenRecord;
import com.sunnada.edu.business.attendance.bean.Attendance;
import com.sunnada.edu.business.attendance.service.AttenRecordService;
import com.sunnada.edu.business.attendance.service.AttendanceService;
import com.sunnada.edu.system.pub.common.BasicController;
import com.sunnada.edu.system.pub.dao.Page;
import com.sunnada.edu.system.pub.service.PubMethods;
import com.sunnada.edu.system.pub.util.Utils;

/***
 * explain 考勤记录
 * 
 * @author zhenglx
 */
@Controller
@RequestMapping("/attenRecordController")
public class AttenRecordController extends BasicController {
	@Resource
	AttenRecordService attenRecordService;
	@Resource
	AttendanceService attendanceService;
	/** 考勤记录首页 */
	@RequestMapping("/attenRecord")
	public String attenRecord(HttpServletRequest request) {
		String curr = request.getParameter("curr");
		request.setAttribute("curr", curr);
		// 当前路径
		String moduleId = request.getParameter("moduleId");
		request.setAttribute("pathValue", PubMethods.getPathValue(moduleId));
		List<?> g = attendanceService.getWorkerGroup(null);
		request.setAttribute("groupList", g);
		return "business/attendance/attenRecord";
	}

	/** 考勤记录查询 */
	@RequestMapping("/attenRecordSearch")
	public void attenRecordSearch(HttpServletRequest request, HttpServletResponse response) {
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, AttenRecord.class, params);
		Page page = new Page();
		page.setRowCount(attenRecordService.getAttenRecordCots(params));
		page.setPageMap(request, page, params);
		List<?> userList = attenRecordService.findAttenRecord(params);
		JSONObject json = new JSONObject();
		json.put("list", userList);
		json.put("params", params);
		printInfo(response, json);
	}

	/** 考勤记录修改页面 */
	@RequestMapping("/attenRecordUpdate")
	public String attendanceUpdate(HttpServletRequest request) {
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, AttenRecord.class, params);
		String num = request.getParameter("num");
		params.put("num", num);
		Map t =attenRecordService.getAttenRecordData(params);
		request.setAttribute("ard", t);
		return "business/attendance/attenRecord_update";
	}
	
	/** 考勤记录保存功能 */
	@RequestMapping("/attenRecordSave")
	public void userSave(HttpServletRequest request, HttpServletResponse response) {
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, AttenRecord.class, params);
		msg = attenRecordService.attenRecordDataUpdate(params);
		printInfo(response, msg);
	}

	/** 考勤导出 */
	@RequestMapping("/exportAttendance")
	public void exportAttendance(HttpServletRequest request, HttpServletResponse response) {
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, AttenRecord.class, params);
		try {
			attenRecordService.exportAttendance(params, request, response);
		} catch (Exception e) {
			printInfo(response, "<script>alert('导出失败，请稍后重试！');window.history.go(-1);</script>");
		}
	}
	
	
	/** 考勤记录首页 */
	@RequestMapping("/attenRecords")
	public String attenRecords(HttpServletRequest request) {
		String curr = request.getParameter("curr");
		request.setAttribute("curr", curr);
		// 当前路径
		String moduleId = request.getParameter("moduleId");
		request.setAttribute("pathValue", PubMethods.getPathValue(moduleId));
		List<?> g = attendanceService.getWorkerGroup(null);
		request.setAttribute("groupList", g);
		return "business/attendance/attenRecords";
	}

	/** 考勤记录查询 */
	@RequestMapping("/attenRecordsSearch")
	public void attenRecordsSearch(HttpServletRequest request, HttpServletResponse response) {
		HashMap<String, String> params = new HashMap<String, String>();
		setReqParams(request, AttenRecord.class, params);
		Page page = new Page();
		page.setRowCount(attenRecordService.getAttenRecordsCots(params));
		page.setPageMap(request, page, params);
		List<?> userList = attenRecordService.findAttenRecords(params);
		JSONObject json = new JSONObject();
		json.put("list", userList);
		json.put("params", params);
		printInfo(response, json);
	}
	
	
}
